package com.entrogy.dao;

import com.alibaba.fastjson.JSONObject;
import com.entrogy.bean.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface StudentScoreMapper {
    /**
     * 查询学生成绩列表
     * @param examId 考试id
     * @param classType 班级类型
     * @param classId 班级id
     * @param scoreTableName 成绩表名
     * @param schoolCode 学校id
     * @param exportScore 是否是导出excel查询需要查询的数据
     * @param studentId 学生id
     * @return
     */
    List<StudentScoreEntity> findStudentScoreList(@Param(value = "examId") Integer examId, @Param(value = "classType") Integer classType, @Param(value = "classId") Integer classId, @Param(value = "scoreTableName") String scoreTableName, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "exportScore") boolean exportScore, @Param(value = "studentId") Integer studentId);

    /**
     * 查找单科目学生的分数
     * @param param
     * @return
     */
    List<StudentCourseScoreEntity> findStudentCourseScoreList(Map<String, Object> param);

    /**
     * 录入学生成绩
     * @param scoreTableName
     * @param studentCourseScoreEntities
     * @return
     */
    int updateStuCourseScore(@Param("scoreTableName") String scoreTableName, @Param("studentCourseScoreEntities") List<StudentCourseScoreEntity> studentCourseScoreEntities);

    /**
     * 查看班级分数概览
     * @param examId
     * @param classId
     * @param scoreTableName
     * @return
     */
    List<ClassScoreOverviewEntity> findClassScoreOverviewList(@Param("examId") Integer examId, @Param("classId")Integer classId, @Param("scoreTableName")String scoreTableName);

    /**
     * 查询科目年级平均分
     * @param examId
     * @param courseId
     * @param gradeId
     * @param scoreTableName
     * @return
     */
    Double findGradeAvgScore(@Param("examId") Integer examId, @Param("courseId")Integer courseId, @Param("gradeId")Integer gradeId, @Param("scoreTableName")String scoreTableName);

    /**
     * 查询科目班级排名
     * @param map
     * @return
     */
    Integer findClassRankForCourse(Map<String, Object> map);

    Integer findStudentClassRank(@Param("studentId") Integer studentId, @Param("classId") Integer classId, @Param("scoreTableName") String scoreTableName, @Param(value = "examId") Integer examId);

    Integer findStudentGradeRank(@Param("studentId") Integer studentId, @Param("gradeId") Integer gradeId, @Param("scoreTableName") String scoreTableName, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "examId") Integer examId);

    List<JSONObject> findStudentScoreListForExport(@Param(value = "examId") Integer examId, @Param(value = "staticCourses") List<StaticCourseEntity> staticCourses, @Param(value = "scoreTableName") String scoreTableName);

    List<StaticCourseEntity> findExamStaticCourse(Integer examId);

    Integer findCourseIdByStaticId(@Param("staticCourseId") Integer staticCourseId, @Param("examId") Integer examId, @Param("studentId") Integer studentId);

    Integer updateScoreByImport(@Param(value = "scoreTableName") String scoreTableName, @Param(value = "studentCourseScore") StudentCourseScoreEntity studentCourseScoreEntity);


    /**
     * 更新课程考试的排名
     * @param id 课程考试成绩id
     * @param classRank 排名
     * @param scoreTableName 表名
     * @return
     */
    Integer updateCourseClassRank(@Param(value = "id") Integer id, @Param(value = "classRank") int classRank, @Param(value = "scoreTableName") String scoreTableName);

    /**
        定时创建成绩表，格式为为exam_score+当前年份+当前月份
     *
     */
    Integer timingCreateScoreTable(@Param(value = "scoreTableName") String scoreTableName);


    /**
     * 查询某一次考试的学生的班级排名
     * @param examId
     * @param classId
     * @param scoreTableName
     * @return
     */
    List<StudentExamRankEntity> listStudentClassRank(@Param(value = "examId") Integer examId, @Param(value = "classId") int classId, @Param(value = "scoreTableName") String scoreTableName);

    /**
     * 更新某一次考试学生的班级排名的数据
     * @param studentExamRank
     * @return
     */
    Integer updateStudentClassRank(StudentExamRankEntity studentExamRank);

    /**
     * 查询某一次考试学生的年级排名的数据
     * @param examId
     * @param scoreTableName
     * @return
     */
    List<StudentExamRankEntity> getStudentGradeRank(@Param("examId") Integer examId, @Param(value = "scoreTableName") String scoreTableName);

    /**
     * 更新某一次考试学生的年级排名的数据
     * @param studentExamRank
     * @return
     */
    Integer updateStudentGradeRank(StudentExamRankEntity studentExamRank);

    /**
     * 更新单科年级排名
     * @param id
     * @param gradeRank
     * @param scoreTableName
     * @return
     */
    Integer updateCourseGradeRank(@Param("id") Integer id, @Param("gradeRank") Integer gradeRank, @Param("scoreTableName") String scoreTableName);

    /**
     * 查询某次考试某个学生某几个科目的总分
     * @param studentId
     * @param examId
     * @param scoreTableName
     * @return
     */
    Double getStudentExamCourseScore(@Param("studentId") Integer studentId, @Param("examId") Integer examId, @Param("cultureStaticCourseId") List<Integer> cultureStaticCourseId, @Param("scoreTableName") String scoreTableName);

    /**
     * 更新某次学生的理综/文综分数
     * @param studentId
     * @param examId
     * @param scienceOrArtsTotalScore
     * @return
     */
    int updateScienceArtsTotalScore(@Param("studentId") Integer studentId, @Param("examId") Integer examId, @Param("scienceOrArtsTotalScore") Double scienceOrArtsTotalScore);

    /**
     * 查询学生的年级理综/文综排名
     * @param examId
     * @return
     */
    List<StudentExamRankEntity> listStudentScienceOrArtsGradeRank(@Param("examId") Integer examId);

    /**
     * 更新学生的排名信息
     * @param studentExamRank
     * @return
     */
    int updateStudentRank(StudentExamRankEntity studentExamRank);

    /**
     * 查询学生的班级理综/文综排名
     * @param examId
     * @return
     */
    List<StudentExamRankEntity> listStudentScienceOrArtsClassRank(@Param("examId") Integer examId, @Param("examClassId") Integer examClassId);

    /**
     * 批量更新学生所考课程的班级排名
     * @param studentCourseScoreList
     * @param scoreTableName
     * @return
     */
    int updateBatchCourseClassRank(@Param("studentCourseScoreList") List<StudentCourseScoreEntity> studentCourseScoreList, @Param("scoreTableName") String scoreTableName);

    /**
     * 批量更新学生所考课程的年级排名
     * @param studentCourseScoreList
     * @param scoreTableName
     * @return
     */
    int updateBatchCourseGradeRank(@Param("studentCourseScoreList") List<StudentCourseScoreEntity> studentCourseScoreList, @Param("scoreTableName") String scoreTableName);
}
